package com.tow.group.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;




/**
 * @author XX
 *
 */
public class DB implements DBI {
	
	//数据库连接符
		private final String URL="jdbc:mysql://localhost:3306/tencent_data?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull";
		private final String USERNAME="root";
		private final String PWD="root";
		private final String DRIVER="com.mysql.jdbc.Driver";
		
		Connection connection;
	
	public DB() {
		// TODO Auto-generated constructor stub
		try {
			//加载驱动类
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Connection getConn() throws SQLException {
		// TODO Auto-generated method stub
		connection = DriverManager.getConnection(URL,USERNAME,PWD);
		return connection;
	}

	public void closeConn() throws SQLException {
		// TODO Auto-generated method stub
		if(connection != null && !connection.isClosed()){
			connection.close();
		}

	}

}
